﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadLibrary.Net.Ndmp
{
    /// <summary>
    /// Holds status of NDM Protocol result.
    /// </summary>
    public enum NdmpStatus
    {
        /// <summary>
        /// Requested operation has been done.
        /// </summary>
        Done,
        /// <summary>
        /// Unexpected uncaught exception has occurred when server was trying to parse and execute request.
        /// </summary>
        Exception,
        /// <summary>
        /// Requested operation hasn't been done.
        /// </summary>
        Undone
    }
    /// <summary>
    /// Serves as manager which transforms NdmpStatus to different forms.
    /// </summary>
    public class NSManager
    {
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents specified NdmpStatus.
        /// </summary>
        /// <param name="status">The status.</param>
        /// <returns>
        /// A <see cref="System.String"/> that represents specified NdmpStatus.
        /// </returns>
        public static string ToString(NdmpStatus status)
        {
            switch (status)
            { 
                case NdmpStatus.Done:
                    return "DONE";
                case NdmpStatus.Exception:
                    return "EXCEPTION";
                case NdmpStatus.Undone:
                    return "UNDONE";
                default:
                    return "UNDONE";
            }
        }
        /// <summary>
        /// Parses specified string to new NdmpStatus.
        /// </summary>
        /// <param name="input">Specifies input string which has to be parsed.</param>
        /// <returns>NdmpStatus parsed from specifieds string.</returns>
        public static NdmpStatus ToStatus(string input)
        {
            switch (input.ToUpper())
            { 
                case "DONE":
                    return NdmpStatus.Done;
                case "EXCEPTION":
                    return NdmpStatus.Exception;
                case "UNDONE":
                    return NdmpStatus.Undone;
                default:
                    return NdmpStatus.Undone;
            }
        }
    }
}
